<extend name="Index/index" />

<block name="Main content" >

<div class="container" >
    <div class="row">
        <div class="col-md-12">
            <div style="padding:3px"></div>
                    <div class="mt20">
                        <a href="<{:U('Discuss/index')}>" class="btn btn-primary">全&nbsp&nbsp&nbsp部</a>&nbsp&nbsp&nbsp
                        <a href="<{:U('Discuss/index',array('condition'=>2))}>" class="btn btn-success">已隐藏</a>&nbsp&nbsp&nbsp
                        <a href="<{:U('Discuss/index',array('condition'=>1))}>" class="btn btn-info">被举报</a>
                    </div>  
                    <div style="padding:3px"></div>
          
                <table class="table table-hover">
                    <tr class="success">
                        <th class="col-md-1">评论ID</th>
                        <th class="col-md-1">对应答案</th>
                        <th class="col-md-5">评论内容</th>
                        <th class="col-md-1">评论时间</th>
                        <th class="col-md-1">评论人</th>
                        <th class="col-md-1">显示状态</th>
                        <th>举报状态</th>
                    </tr>
                    <volist name="list" id="v">
                    <tr>
                        <td><{$v.id}></td>
                       
                        <td><a href="<{:U('Home/Discuss/detail', array('qid'=>$v['qid'],'aid'=>$v['answer_id']))}>" target="_blank"><{$v.answer_id}></a></td>
                        <td><{$v.content}></td>
                        <td><{$v.datetime}></td>
                        <td><{$v.name}></td>
                   
                        <!-- 显示状态 -->
                        <td>
                            <if condition="$v.display eq '0' "><button class="btn btn-danger display" qsid="<{$v.id}>"><span class="glyphicon glyphicon-remove"></span></button>
                            <else/>
                            <button class="btn btn-success display" qsid="<{$v.id}>"><span class="glyphicon glyphicon-ok"></span></button></if>
                        </td>
                            <!-- 举报状态 -->
                        <td>
                            <if condition="$v.report eq '0' "><button class="btn btn-success report" qsid="<{$v.id}>"><span class="glyphicon glyphicon-ok"></span></button>
                            <else/>
                            <button class="btn btn-warning report" qsid="<{$v.id}>"><span class="glyphicon glyphicon-exclamation-sign"></span></button></if>
                        </td>
        <!-- 
                        <td class="col-md-2">
                            <a class="btn btn-sm btn-primary" qsid="<{$v.id}>" href="<{:U('Discuss/edit',array('id'=>$v['id']))}>">编辑</a>
                        </td> -->
                    </tr>

                    </volist>
                </table>
                <div style="margin-left:10px"><{$page}></div>
            </div>
    </div> <!-- row结束 -->
</div> <!--container结束 -->

</block>

<block name="myjs">
    <script>



        $(document).ready(function(){
            console.log(1);
            var display = $('button.display');
            for (var i = 0; i < display.length; i++) {
                $(display[i]).click(function(){
                    console.log($(this));
                    var qsid = $(this).attr('qsid');
                    // 判断button的状态
                    if ($(this).html() == '<span class="glyphicon glyphicon-ok"></span>') {
                        $.ajax({
                            type: 'get',
                            url: "<{:U('Discuss/ds_display')}>",
                              data: 'id=' + $(this).attr('qsid')+'&display=1',

                        });
                        $(this).html('<span class="glyphicon glyphicon-remove">').removeClass('btn-success').addClass('btn-danger');
                    } else {
                        $.ajax({
                            type: 'get',
                            url: "<{:U('Discuss/ds_display')}>",
                            data: 'id=' + $(this).attr('qsid')+'&display=0',
                        });
                        $(this).html('<span class="glyphicon glyphicon-ok"></span>').removeClass('btn-danger').addClass('btn-success');
                    };

                                
                    return false; //阻止跳转
                });
            }; // 状态点击事件结束
             //切换举报状态
        var report = $('button.report');
            for (var i = 0; i < report.length; i++) {
                $(report[i]).click(function(){
                    // console.log($(this));
                    var qsid = $(this).attr('qsid');
                    // 判断button的状态
                    if ($(this).html() == '<span class="glyphicon glyphicon-ok"></span>') {
                        $.ajax({
                            type: 'get',
                            url: "<{:U('Discuss/report')}>",
                              data: 'id=' + $(this).attr('qsid')+'&report=0',
                        });
                        $(this).html('<span class="glyphicon glyphicon-exclamation-sign">').removeClass('btn-success').addClass('btn-warning');
                    } else {
                        $.ajax({
                            type: 'get',
                            url: "<{:U('Discuss/report')}>",
                            data: 'id=' + $(this).attr('qsid')+'&report=1',
                        });
                        $(this).html('<span class="glyphicon glyphicon-ok"></span>').removeClass('btn-warning').addClass('btn-success');
                    };

                                
                    return false; //阻止跳转
                });
            }; // 切换举报事件结束


        });
    </script>
</block>